<?php
include('./includes.php');

$q0 = mysql_query("SELECT * FROM ".tSettings)or die(mysql_error());
$show0 = mysql_fetch_object($q0);

$q1 = mysql_query("SELECT * FROM ".tPages." WHERE id = '".sql(id)."'")or die(mysql_error());
$show = mysql_fetch_object($q1);

$q2 = mysql_query("SELECT * FROM ".tSections." WHERE page = '".sql($show->id)."' OR page = '0' ORDER BY oid ASC")or die(mysql_error());
while($s = $show2 = mysql_fetch_object($q2))
{
	$sid = v($s->id);
	
    $mod['id']     = $show2->id;
    $mod['block']  = $show2->block;
    
    // Normal Mod Pre and Post
    $mod['pre']    = between($show2->pre, '{', '}');
    $mod['post']   = between($show2->post, '{', '}');
    
    $seSQL = query("SELECT title,blocktemplate FROM ".tSections." WHERE id = '".sql($sid)."'");
    $sList = mysql_fetch_object($seSQL);
    
    $block['title'] = v($sList->title);
    if($sList->blocktemplate == 'Default' || $sList->blocktemplate == '')
    {
        $block['tmp'] = $settings->default_block;
    }
    else
    {
        $block['tmp'] = $sList->blocktemplate;
    }
    
	if(empty($sectionz['section:'.$show2->section]))
	{
		$sectionz['section:'.$show2->section] = '';
	}
	
	if(file_exists($show2->module))
	{
        $sectionz['section:'.$show2->section] .= buffer($show2->module);
	}
}

$sectionz['sitename'] = (isset($show0->site_name)) ? v($show0->site_name) : '';
$sectionz['title']    = (isset($show->title))      ? v($show->title)      : '';

$template3 = buffer($template2);

echo replaceTag($template3, $sectionz);
